/** 
	@file ConfigureDialog.cpp
	@brief Configure Dialog box handler
*/
/*
pGina ldapAuth code - based upon skeleton code for pGina plugin development
Copyright (C) 2002 Micah Cooper

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Email: coopermj@muohio.edu
Snail Mail:
	Micah Cooper
	212A Kreger Hall
	Miami University
	Oxford OH  45056
*/
// ConfigureDialog.cpp : implementation file
//

#include "stdafx.h"
#include "winLDAP.h"
#include "ConfigureDialog.h"
#include "Resource.h"
#include ".\configuredialog.h"


// CConfigureDialog dialog

IMPLEMENT_DYNAMIC(CConfigureDialog, CDialog)
CConfigureDialog::CConfigureDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CConfigureDialog::IDD, pParent)
{
}

CConfigureDialog::~CConfigureDialog()
{
}

void CConfigureDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CONFIG_TAB, m_tabMyTabCtrl);
}


BEGIN_MESSAGE_MAP(CConfigureDialog, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDOK, OnSave)
END_MESSAGE_MAP()


// CConfigureDialog message handlers
BOOL CConfigureDialog::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	//ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	//ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		//strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			//pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	m_tabMyTabCtrl.InsertItem(0, _T("LDAP Configuration"));
	m_tabMyTabCtrl.InsertItem(1, _T("User Configuration"));
	m_tabMyTabCtrl.InsertItem(2, _T("Password Configuration"));
	m_tabMyTabCtrl.InsertItem(3, _T("Hook Configuration"));
	m_tabMyTabCtrl.InsertItem(4, _T("About"));

	m_tabMyTabCtrl.Init();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CConfigureDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
	//if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	//{
	//	CAboutDlg dlgAbout;
	//	dlgAbout.DoModal();
	//}
	//else
	//{
		CDialog::OnSysCommand(nID, lParam);
	//}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CConfigureDialog::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
	}
	else
	{
		CDialog::OnPaint();
	}
}


void CConfigureDialog::OnSave()
{
	// TODO: Add your control notification handler code here
	m_tabMyTabCtrl.OnSave();
	MessageBox(TEXT("Settings Saved"),TEXT("LDAPAuth"), MB_ICONINFORMATION | MB_OK);
	OnOK();
}
